import sys
from my_action.srv import JointPosition
import rclpy
from rclpy.node import Node


class JointPositionClient(Node):

    def __init__(self, name):
        super().__init__(name)
        self.cli = self.create_client(JointPosition, 'joint_position')
        self.tf_buffer = Buffer()
        self.tf_listener = TransformListener(self.tf_buffer, self)
        while not self.cli.wait_for_service(timeout_sec=1.0):
            self.get_logger().info('service not available, waiting again...')

    def send_request(self, joint_type):
        self.req = JointPosition.Request()
        self.req.joint_type = str(joint_type)
        future = self.cli.call_async(self.req)
        rclpy.spin_until_future_complete(self, future)
        response = future.result().joint_position
        return response


def main(args=None):
    rclpy.init(args=args)

    minimal_client = MinimalClientAsync()
    print('start')
    minimal_client.send_request("raise")

    minimal_client.destroy_node()
    rclpy.shutdown()


if __name__ == '__main__':
    main()